package graph;

import java.util.LinkedList;
import java.util.NoSuchElementException;

public class LinkedEdgeList<E extends Edge> extends LinkedList<Edge> {

	public boolean isThereEdgeBetween(Node from, Node to) {
		for(Edge edge : this) {
			if(edge.getFromNode().equals(from) && edge.getToNode().equals(to))
				return true;
		}
		
		return false;
	}
	
	public Edge getEdgeBetween(Node from, Node to) {
		if(from == null || to == null)
			throw new IllegalArgumentException("Parameter must not be null");
		
		for(Edge edge : this) {
			if(edge.getFromNode().equals(from) && edge.getToNode().equals(to))
				return edge;
		}
		
		throw new NoSuchElementException("No edge between " + from + " and " + to + ".");
	}
	
}
